package com.fintech.third.service.message;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fintech.third.constant.PageConstant;
import com.fintech.third.dao.PushMessageInfoMapper;
import com.fintech.third.model.facesign.JsonResult;
import com.fintech.third.model.message.MessageInfoPageConditionDto;
import com.fintech.third.model.message.PushMessageInfo;
import com.fintech.third.service.PushDefineBatchSend;
import com.marvels.common.utils.MarvelsLogUtil;


@Service("PushFace")
public class PushFaceSignImpl implements PushFaceSigService {
	@Autowired
	private PushMessageInfoMapper pushMessageInfoMapper;

	@Autowired
	PushMessageCategoryService pushMessageCategoryService;
	@Override
	public JsonResult<String> pushFacePush(Map<String, String> map) {
		JsonResult<String> jsonResult = new JsonResult<String>();
		return jsonResult;
	}

	@Override
	public Boolean insertTimingPush(List<PushMessageInfo> list) {
		try {
			pushMessageInfoMapper.insertPushMessageBath(list);
			return true;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>批量插入消息推送异常:",e);
			return false;
		}

	}

	@Override
	public Boolean pushSendDefineTemplate(final List<PushDefineBatchSend> list) {
		return true;
	}

	@Override
	public List<PushMessageInfo> pushMessageInfoPage(MessageInfoPageConditionDto messageInfoPageConditionDto) {
		List<PushMessageInfo> list=null;
		if(messageInfoPageConditionDto!=null){
			if(messageInfoPageConditionDto.getCurrPage()<1){
				messageInfoPageConditionDto.setCurrPage(PageConstant.currPage);
			}
			if(messageInfoPageConditionDto.getPageSize()<1){
				messageInfoPageConditionDto.setPageSize(PageConstant.pageSize);
			}
			int startPage = (messageInfoPageConditionDto.getCurrPage()-1) * messageInfoPageConditionDto.getPageSize();  
			int endPage =messageInfoPageConditionDto.getPageSize();
			messageInfoPageConditionDto.setStartPage(startPage);
			messageInfoPageConditionDto.setEndPage(endPage);
			try{
				list=pushMessageInfoMapper.pushMessageInfoPage(messageInfoPageConditionDto);
			}catch(Exception e){
				e.printStackTrace();
				MarvelsLogUtil.getInstance().info("===========消息分页异常:"+e.getMessage());
			}
		}
		return list;
	}

	@Override
	public int countAllMessageInfo(String userId) {
		return pushMessageInfoMapper.countAllMessageInfo(userId);
	}

	@Override
	public int updateMessageReadStatus(String messageId) {
		return pushMessageInfoMapper.updateMessageReadStatus(messageId);
	}

	@Override
	public int deleteMessageBatch(String userId) {
		
		return pushMessageInfoMapper.deleteMessageBatch(userId);
	}

}
